import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:yx_flutter/YXLocalizations.dart';
import 'package:yx_flutter/provider/base.dart';

// 有眼睛的textField
class udpatePaswordTextField extends StatelessWidget {
  // textField的Controller
  TextEditingController controller;
  // 填充
  String placeholder;
  // 初始化
  udpatePaswordTextField(
      {@required this.controller, @required this.placeholder});

  @override
  Widget build(BuildContext context) {
    // 星星状态记录
    udpatePaswordTextFieldModel paswordProvide =
        Provider.of<udpatePaswordTextFieldModel>(context);

    return Container(
      margin: EdgeInsets.only(left: 37, right: 37, top: 20),
      padding: EdgeInsets.only(left: 20),
      decoration: BoxDecoration(
        color: Color(0xfff7f7f7),
        borderRadius: BorderRadius.circular(23.0),
      ),
      height: 46,
      child: TextField(
        obscureText: paswordProvide.obscureText,
        controller: controller,
        decoration: InputDecoration(
          border: InputBorder.none,
          hintText: YXLocalizations.share().localString(placeholder),
          // contentPadding: EdgeInsets.only(left: 20, top: 15),
          fillColor: Colors.red,
          hintStyle: TextStyle(
            color: Color(0xff99A2AB),
          ),
          suffixIcon: SizedBox(
            height: 47,
            width: 70,
            child: FlatButton(
                padding: const EdgeInsets.all(10),
                // color: Colors.green,
                highlightColor: Colors.transparent,
                splashColor: Colors.transparent,
                child: Image.asset(
                  paswordProvide.obscureText
                      ? 'images/YXMe_closeEye_w.png'
                      : 'images/YXMe_eye_w.png',
                  width: 50,
                ),
                // shape: RoundedRectangleBorder(
                // borderRadius: BorderRadius.circular(20)),
                onPressed: () {
                  paswordProvide.changeObscureText();
                }),
          ),
        ),
      ),
    );
  }
}

// 管理输入框样式改变
class udpatePaswordTextFieldModel extends BaseProvide {
  // true 不明文显示 false 明文显示 默认不明文
  bool obscureText = true;
  // 改变输入框状态
  void changeObscureText() {
    obscureText = !obscureText;
    notifyListeners();
  }
}
